package com.open.dome.order.controller;

import com.alibaba.fastjson.JSONObject;
import com.open.dome.order.param.WorkOrderPageForm;
import com.open.dome.order.param.WorkOrderPageParam;
import com.open.dome.until.HttpUntil;
import com.open.dome.until.SignUntil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;

@RestController
@RequestMapping("/test")
public class TestController {

    private final static String appKey = "9WRvQGD5";
    private final static String secret = "1181dcbac4d39692ea3a3dbe9a48f0dc63ab22a7";
    //   private final static  String url = "http://39.98.178.241:9002/open/api/";
    //  private final static  String url = "http://192.168.2.5:9002/open/api/"; demo
    private final static  String url = "http://192.168.138.1:9002/open/api/";


    @GetMapping("/get")
    public Object gets(){
            WorkOrderPageForm workOrderPageForm = new WorkOrderPageForm();
            Long nowTime = System.currentTimeMillis();
            workOrderPageForm.setAppKey(appKey);
            workOrderPageForm.setTimestamp(nowTime);

            //填充参数
            WorkOrderPageParam workOrderPageParam = new WorkOrderPageParam();
            workOrderPageParam.setState(1);
            workOrderPageParam.setStartTime(LocalDate.of(2025, 2, 1));
            workOrderPageParam.setEndTime(LocalDate.of(2025, 2, 27));

            workOrderPageForm.setParam(JSONObject.toJSONString(workOrderPageParam));
            String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(workOrderPageParam), nowTime);
            workOrderPageForm.setSign(sign);

            //发请求
            String s = HttpUntil.doPostJson(url + "workOrderPage", JSONObject.toJSONString(workOrderPageForm));
            System.out.println("结束工单接口返回"+s);
        return s;
    }

}
